<template>
    <!-- 年度下拉框 -->
    <a-select v-bind="$attrs" v-on="$listeners" :placeholder="placeholder" v-model="currentValue" allowClear>
        <a-spin v-if="fetching" slot="notFoundContent" size="small" />
        <a-select-option :disabled="!item.enabled" v-else v-for="(item, index) in list" :key="item.id" :value="item.id">{{ item.name }}</a-select-option>
    </a-select>
</template>
<script>
import { typesLabelList } from '@/api/science'
import { getResponseYear } from '@/api/science/quantufiyResponse'

export default {
    name: 'SelectFormat',
    inheritAttrs: false,
    props: {
        // v-model绑定的数据
        value: {
            type: [Array, String],
        },
        // 需要联动的表单名，
        form: {
            type: Object,
            default: function () {
                return {}
            },
        },
        // placeholder
        placeholder: {
            type: String,
            default: function () {
                return '请选择'
            },
        },
        // 是否获取全部列表（包括停用项）
        isAll: {
            type: Boolean,
            default() {
                return true
            },
        },
    },
    data() {
        return {
            fetching: false,
            list: [],
        }
    },
    mounted() {
        this.getList()
    },
    methods: {
        getList() {
            this.fetching = true
            let params = {}
            getResponseYear(params).then((res) => {
              this.fetching = false
              if (res.code == 200) {
                this.list = res.data.map((item) => {
                  return {
                    id: item,
                    name: item,
                    enabled: true
                  }
                })
              }
            }).catch(() => {
              this.fetching = false
            })
        },
    },
    computed: {
        // 转换绑定的选中数据，与v-model同步
        currentValue: {
            get: function () {
                return this.value
            },
            set: function (value) {
                this.$emit('input', value)
            },
        },
    },
}
</script>
